<template>
	<view class="index-box" :style="{ '--color': vuex_config.themeColor1, '--price': vuex_config.price }">
		<!-- 快递地址 -->
		<sww-wx-address></sww-wx-address>

		<view class="box">
			<!--  规格信息 -->
			<prod-list :selectList="selectList"></prod-list>
			<!-- 优惠券、备注 -->
			<order-cell
				ref="order_cell"
				:hasCoupon="false"
				v-model="couponPrice"
				:prodPostage="prodPostage"
				:productIds="productIds"
				:prodPrice="allProdPrice"
				:service_charge="service_charge"
			></order-cell>
		</view>
		<!-- 支付方式 -->
		<view class="box"><sww-pay-type v-model="dataForm.pay_type" :price="totalPrice + service_charge"></sww-pay-type></view>

		<sww-goods-action>
			<view class="sub-price">
				<text class="">合计：</text>
				<text class="all_price_sign">￥</text>
				<text class="all_price_num">{{ $price(totalPrice + service_charge) }}</text>
			</view>
			<view class="sub-btn" @click="onSubmit">提交订单</view>
		</sww-goods-action>
	</view>
</template>
<script>
import { payOrder } from '@/mixins/payOrder';
import { confirm } from '../components/orderConfirm/index.js';
import prodList from '../components/orderConfirm/prodList.vue';
import orderCell from '../components/orderConfirm/orderCell.vue';
import { isMobile } from '@/utils/validate.js';
export default {
	mixins: [confirm, payOrder],
	components: {
		prodList,
		orderCell
	},
	data() {
		return {
			couponPrice:0,
			order_type: 14,
			checkPick: false, // 是否选择了自提地址
			templateIds: [], // 订阅模板
			service_charge: 0, // 服务费
			order_id:'',
			order_no:'',
			goBack:false
		};
	},
	methods: {
		specialHandle (options) {
			if(options.order_id){
				this.order_id = options.order_id
				this.order_no = options.order_no
			}
			if(options.goBack){
				this.goBack = true
			}
			if(options.coupon){
				// 暂且不支持优惠券
				this.couponPrice = Number(options.coupon)
			}
		},
		finshedCall() {
			this.service_charge = Number(this.selectList[0].service_charge);
		},
		// 提交表单
		onSubmit() {
			this.$u.debounce(
				() => {
					if (!this.vuex_address) {
						this.$toast('请选择收货地址');
						return;
					}
					// 当前地址是否在配送区域
					if (!this.$checkCanBuyFromPostageModule()) return;
					// this.getBondDetail().then(() => {
						this.$loading()
						let obj = {
							pk_id:this.order_id,
							...this.vuex_address,
							postage:this.checkPick ? 0 : this.prodPostage,
							remark:this.$refs.order_cell.remark || '',
							total_amount:this.totalPrice + this.service_charge, // 订单总金额
						}
						this.$resPost('UpdateOrderInfo',obj).then(()=>{
							let opts = {
								totalPrice: obj.total_amount,//支付金额
								order_type: this.order_type,//余额支付订单类型
								remark:obj.remark,//余额扣款备注
								updateApi:'UpdateOrderStatus', // 更新接口
								pay_type:this.dataForm.pay_type,//支付方式
							}
							this.judgeTypeToPay({order_no:this.order_no},opts).then((res)=>{
								this.$hide()
								if(this.goBack){
									this.uniBack()
								}else{
									this.$linkTo('/package/order/list/index','redirectTo')
								}
							}).catch((err)=>{
								if (err) {
									this.$toast({
										title: err
									})
								}
								setTimeout(()=>{
									if(this.goBack){
										this.uniBack()
									}else{
										this.$linkTo('/package/order/list/index','redirectTo')
									}
								},1000)
							})
						})
					// });
				},
				1000,
				true
			);
		},
		// getBondDetail() {
		// 	return new Promise((resolve, reject) => {
		// 		this.$loading()
		// 		this.$resPost('GetUsersDepositInfo', { page: 1, page_size: 1 }).then(({ data }) => {
		// 			if (data[0]) {
		// 				this.depositInfo = {
		// 					...data[0]
		// 				};
		// 			}
		// 			this.$hide()
		// 			resolve()
		// 		}).catch(()=>{reject()})
		// 	});
		// }
	}
};
</script>
<style>
page {
	background-color: #f5f5f5;
}
</style>
<style lang="scss" scoped>
.index-box {
	width: 100%;
	.box {
		width: 100%;
		padding: 0 24rpx;
		background-color: #ffffff;
		margin-bottom: 10rpx;
	}

	.sub-price {
		padding-left: 30rpx;
		font-size: 32rpx;
		.all_price_sign {
			color: var(--price);
			font-size: 30rpx;
		}
		.all_price_num {
			font-size: 40rpx;
			color: var(--price);
		}
	}

	.sub-btn {
		width: 250rpx;
		height: 100rpx;
		background: var(--color);
		display: flex;
		align-items: center;
		justify-content: center;
		color: #ffffff;
		font-size: 30rpx;
		margin-left: auto;
	}
}
</style>
